#from ChessBoard import ChessBoard
from ChessConsts import ChessConsts
    # Sue and Zaid

def checkKingGuard(chessboard,fromPos,moves,specialMoves={}):
	result = []
	if chessboard._turn == ChessConsts.WHITE:
		kx,ky = chessboard._white_king_location
	else:
		kx,ky = chessboard._black_king_location

	fx,fy = fromPos

  	done = False
        fp = chessboard._board[fy][fx]
        chessboard._board[fy][fx] = "."
        if not chessboard.isThreatened(kx,ky):
        	done = True
        chessboard._board[fy][fx] = fp

        if done:
        	return moves

        for m in moves:
        	tx,ty = m
            	sp = None
            	fp = chessboard._board[fy][fx]
            	tp = chessboard._board[ty][tx]

           	chessboard._board[fy][fx] = "."
            	chessboard._board[ty][tx] = fp

            	if specialMoves.has_key(m) and specialMoves[m] == chessboard.EP_CAPTURE_MOVE:
                	sp = self.chessboard._board[self.chessboard._ep[1]][self.chessboard._ep[0]]
                	chessboard._board[self.chessboard._ep[1]][self.chessboard._ep[0]] = "."

            	if not chessboard.isThreatened(kx,ky):
                	result.append(m)

            	if sp:
                	chessboard._board[chessboard._ep[1]][chessboard._ep[0]] = sp

            	chessboard._board[fy][fx] = fp
            	chessboard._board[ty][tx] = tp

        return result
